<?php

        session_start();

        include('common.php');
        include('../includes/pager.php');

    if (session_is_registered(MySBB_Admin_username) and $member_permission == 1)
    {

/*************************************************************************/

            if ($groupper_row['admincp_icon'] != 1)
        {
                $SF->error('المعذره .. هذه الميزه غير متاحه لك !');
        }

/*************************************************************************/

             if ($_GET['add'] == 1)
        {
                      if ($_GET['index'] == 1)
            {
                                   $SF->Make_cplink_path('<a href="avatar.php?main=1">الايقونات</a> -> اضافة ايقونه');

                               $Smarty->display('icon_add.tpl');
                      }

                      if ($_GET['start'] == 1)
            {
                               if (empty($_POST['T1']))
                {
                                $SF->error('يرجى تعبئة كافة المعلومات');
                               }

                               $insert = $DB->sql_query("INSERT INTO " . $db_prefix . "smiles(id,smile_path,smile_type) VALUES('NULL','" . $_POST['T1'] . "','1')");

                if ($insert)
                {
                                $SF->msg('تم اضافة الايقونه بنجاح !');
                                $SF->go_to('icon.php?main=1',2);
                               }
                      }
             }

/*************************************************************************/

             if ($_GET['main'] == 1)
        {
                 if (!isset($_GET['page']) OR $_GET['page'] < 1)
                 {
                     $_GET['page'] = 1;
                 }

                 $page  = intval($_GET['page']);
                 $start = ($info_row['perpage'] * ($page-1));

                 $RP = new Pager($page);

                      $smiles_query = $DB->sql_query("SELECT * FROM " . $db_prefix . "smiles WHERE smile_type='1' ORDER BY id ASC LIMIT $start," . $info_row['perpage'] ."");

                      $RP->SetPagerN($info_row['perpage'],$DB->sql_num_rows($DB->sql_query("SELECT * FROM " . $db_prefix . "smiles WHERE smile_type='1'")));

                      $smiles_row = array();

                      while ($smile_row = $DB->sql_fetch_array($smiles_query))
            {
                               $smiles_row[] = $smile_row;

                               $Smarty->assign('smiles_row',$smiles_row);
                      }

                          $SF->Make_cplink_path('الايقونات');

                      print $RP->PageNum('main=1');

            $Smarty->display('icon_main.tpl');
             }

/*************************************************************************/

             if ($_GET['edit'] == 1)
        {
                      if ($_GET['index'] == 1)
            {
                               $getsmile_query = $DB->sql_query("SELECT * FROM " . $db_prefix . "smiles WHERE id='" . intval($_GET['id']) . "'");
                               $getsmile_row   = $DB->sql_fetch_array($getsmile_query);

                               $Smarty->assign_by_ref('getsmile_row',$getsmile_row);

                                   $SF->Make_cplink_path('<a href="avatar.php?main=1">الايقونات</a> -> تحرير ايقونه');

                               $Smarty->display('icon_edit.tpl');
                      }

                     if ($_GET['start'] == 1)
                {
                              if (empty($_POST['T1']) or empty($_POST['T2']))
                    {
                                       $SF->error('يرجى تعبئة كافة المعلومات');
                              }

                              $insert = $DB->sql_query("UPDATE " . $db_prefix . "smiles SET smile_path='" . $_POST['T1'] . "',smile_short='" . $_POST['T2'] . "' WHERE id='" . $id . "'");

                    if ($insert)
                    {
                                       $SF->msg('تم التحديث بنجاح !');
                                       $SF->go_to('icon.php?main=1',2);
                              }
                     }
             }


/*************************************************************************/

             if ($_GET['del'] == 1)
        {
                      $del = $DB->sql_query("DELETE FROM " . $db_prefix . "smiles WHERE id='" . intval($_GET['id']) . "'");

                      if ($del)
            {
                               $SF->msg('تم الحذف بنجاح !');
                               $SF->go_to('icon.php?main=1',2);
                      }
             }

/*************************************************************************/

    }

?>